package com.dr.cmdb.core.kafka.producer;

import com.dr.cmdb.core.kafka.MqMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;


import java.util.Date;
import java.util.UUID;

/**
 * @ProjectName: cmdb
 * @Package: com.dr.cmdb.application.kafka.producer
 * @Description: java类作用描述
 * @Author: duanrui
 * @CreateDate: 2021/4/14 18:06
 * @Version: 1.0
 * <p>
 * Copyright: Copyright (c) 2021
 */
@Component
public class KafkaSender {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    //发送消息方法
    public void send() {
        MqMessage message = new MqMessage();
        message.setId(System.currentTimeMillis());
        message.setMsg(UUID.randomUUID().toString());
        message.setSendTime(new Date());
        kafkaTemplate.send("test", JSON.toJSONString(message));
    }
}
